package com.sjt.thread;

public class InterruptTest{

    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {

                    // 判断是否有中断标志
                    if (Thread.interrupted()) {
                        System.out.println("线程被中断");
                        break;
                    }
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("线程执行"+ i);
                }
            }
        });
        thread.start();
        Thread.sleep(10);
        thread.interrupt();
        for (int i = 0; i < 10; i++) {

            System.out.println("main"+i);
        }
    }

}
